package com.gameloops;

// http://www.koonsolo.com/news/dewitters-gameloop/
public class Gameloop4 extends Thread {
	final int TICKS_PER_SECOND = 25;
	final int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
	final int MAX_FRAMESKIP = 5;
	private long startTime = 0;
    
    long next_game_tick = getTickCount();
    int loops;
    float interpolation;
    
    public Gameloop4()
    {
    	this.startTime = getTickCount();
    }
    
    public void run()
    {
    	boolean game_is_running = true;
        while( game_is_running ) {

            loops = 0;
            while( getTickCount() > next_game_tick && loops < MAX_FRAMESKIP) {
                update_game();

                next_game_tick += SKIP_TICKS;
                loops++;
            }

            interpolation = (float)( getTickCount() + SKIP_TICKS - next_game_tick )
                            / (float)( SKIP_TICKS );
            display_game( interpolation );
        }
    }
    
    private long getTickCount()
    {
    	return System.nanoTime() / 1000000;
    }
    
    private void update_game()
    {
    	
    }
    
    private void display_game(float interpolation)
    {
    	System.out.println(interpolation);
    }
}
